package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface RoleDao {
    @Select("select * from t_role")
    public List<Role> findAll();

    Page<Role> selectAllByName(String queryPageBean);

    void update(Role role);

    @Delete("delete from t_role_permission where role_id = #{id}")
    void deletePermission(Integer id);

    @Insert("insert into t_role_permission values(#{rid},#{pid})")
    void add(@Param("pid") Integer permissionId,@Param("rid") Integer id);

    void addRole(Role role);

    @Insert("insert into t_role_menu values(#{rid},#{mid})")
    void addMenu(@Param("mid") Integer menuId,@Param("rid") Integer id);

    @Delete("delete from t_role_menu where role_id = #{id}")
    void deleteMenu(Integer id);

    @Select("select * from t_role r,t_role_permission rp where r.id = rp.role_id and rp.permission_id = #{id}")
    public Set<Role> findRoleByPermission(int id);

    @Select("select count(*) from t_role_permission where role_id = #{id}")
    Integer findPermissionById(int id);

    @Select("select count(*) from t_user_role where role_id = #{id}")
    Integer findUserByid(int id);

    @Select("select count(*) from t_role_menu where role_id = #{id}")
    Integer findMenuByid(int id);

    @Delete("delete from t_role where id = #{id}")
    void delete(int id);
}
